package com.xdcplus.web.controller;



import com.xdcplus.mom.controller.AbstractController;
import com.xdcplus.exceptions.domain.ResponseVO;

import com.xdcplus.pager.vo.PageVO;
import com.xdcplus.web.common.pojo.dto.CraftCheckOrderTargetDTO;
import com.xdcplus.web.common.pojo.dto.CraftCheckOrderTargetFilterDTO;
import com.xdcplus.web.common.pojo.vo.CraftCheckOrderTargetVO;
import com.xdcplus.web.service.CraftCheckOrderTargetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Validation;
import javax.validation.constraints.NotNull;


/**
 * 点检工单明细表(CraftCheckOrderTarget)表服务控制层
 *
 * @author Man.Chen
 * @since 2024-12-03 17:43:56
 */
@Api(tags = "点检工单明细表(CraftCheckOrderTarget)") 
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("craftCheckOrderTarget")
public class CraftCheckOrderTargetController extends AbstractController {

    @Autowired
    private CraftCheckOrderTargetService craftCheckOrderTargetService;

    @ApiOperation("新增点检工单明细表")
    @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO saveCraftCheckOrderTarget(@RequestBody CraftCheckOrderTargetDTO craftCheckOrderTargetDTO) {

        log.info("saveCraftCheckOrderTarget {}", craftCheckOrderTargetDTO.toString());

        craftCheckOrderTargetDTO.setCreatedUser(getAccount());
        craftCheckOrderTargetService.saveCraftCheckOrderTarget(craftCheckOrderTargetDTO);

        return ResponseVO.success();
    }

    @ApiOperation("修改点检工单明细表")
    @PutMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO updateCraftCheckOrderTarget(@RequestBody CraftCheckOrderTargetDTO craftCheckOrderTargetDTO) {

        log.info("updateCraftCheckOrderTarget {}", craftCheckOrderTargetDTO.toString());

        craftCheckOrderTargetDTO.setUpdatedUser(getAccount());
        craftCheckOrderTargetService.updateCraftCheckOrderTarget(craftCheckOrderTargetDTO);

        return ResponseVO.success();
    }

    @ApiOperation("删除点检工单明细表")
    @DeleteMapping(value = "/{craftCheckOrderTargetId}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "craftCheckOrderTargetId", dataTypeClass = Long.class, value = "点检工单明细表ID", required = true),
    })
    public ResponseVO deleteCraftCheckOrderTargetLogical(@PathVariable("craftCheckOrderTargetId")
                                         @NotNull(message = "点检工单明细表ID不能为空") Long craftCheckOrderTargetId) {

        log.info("deleteCraftCheckOrderTargetLogical {}", craftCheckOrderTargetId);

        craftCheckOrderTargetService.deleteCraftCheckOrderTargetLogical(craftCheckOrderTargetId);

        return ResponseVO.success();
    }
    
    @ApiOperation("批量删除点检工单明细表")
    @DeleteMapping(value = "/deleteByIds/{craftCheckOrderTargetIds}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "craftCheckOrderTargetId", dataTypeClass = Long.class, value = "点检工单明细表ID", required = true),
    })
    public ResponseVO deleteCraftCheckOrderTargetLogical(@PathVariable("craftCheckOrderTargetIds")
                                         @NotNull(message = "点检工单明细表ID不能为空") String craftCheckOrderTargetIds) {

        log.info("deleteCraftCheckOrderTargetByIds {}", craftCheckOrderTargetIds);

        craftCheckOrderTargetService.deleteCraftCheckOrderTargetByIds(craftCheckOrderTargetIds);

        return ResponseVO.success();
    }

    @ApiOperation("查询点检工单明细表")
    @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<PageVO<CraftCheckOrderTargetVO>> findCraftCheckOrderTarget(CraftCheckOrderTargetFilterDTO craftCheckOrderTargetFilterDTO) {

        log.info("findCraftCheckOrderTarget {}", craftCheckOrderTargetFilterDTO);

        Validation.buildDefaultValidatorFactory().getValidator().validate(craftCheckOrderTargetFilterDTO);

        return ResponseVO.success(craftCheckOrderTargetService.queryCraftCheckOrderTarget(craftCheckOrderTargetFilterDTO));
    }


}
